<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>雇员管理</title>
	<link href="../../../../component/pear/css/pear.css" rel="stylesheet" />
</head>
<body class="pear-container">
<div class="layui-card">
	<div class="layui-card-body">
		<form class="layui-form" action="">
			<div class="layui-form-item">
				<div class="layui-form-item layui-inline">
					<label class="layui-form-label">老人姓名</label>
					<div class="layui-input-inline">
						<input type="text" name="patientName" value="" placeholder="" class="layui-input">
					</div>

					<label class="layui-form-label">入住时间</label>
					<div class="layui-input-inline">
						<input type="date" name="checkInDate" value=""  placeholder="" class="layui-input">
					</div>
					<label class="layui-form-label">退住时间</label>
					<div class="layui-input-inline">
						<input type="date" name="checkOutDate" value="" placeholder="" class="layui-input">
					</div>
				</div>

				<div class="layui-form-item layui-inline">
				<label class="layui-form-label">结账时间</label>
				<div class="layui-input-inline">
					<input type="date" name="checkOutTime" value="" placeholder="" class="layui-input">
				</div>
				</div>

				<div class="layui-form-item layui-inline" style="margin-left: 630px">
					<button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="village-query">
						<i class="layui-icon layui-icon-search"></i>
						查询
					</button>
					<button type="reset" class="pear-btn pear-btn-md">
						<i class="layui-icon layui-icon-refresh"></i>
						重置
					</button>
				</div>
			</div>
		</form>
	</div>
</div>
<div class="layui-card">
	<div class="layui-card-body">
		<table id="village_table" lay-filter="village_table"></table>
	</div>
</div>

<script type="text/html" id="role-toolbar">
	<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add">
		<i class="layui-icon layui-icon-add-1"></i>
		新增退住
	</button>

</script>

<script type="text/html" id="role-bar">
	<button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="check">查看</button>
	<button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="remove"><i class="layui-icon layui-icon-delete"></i></button>
</script>


<script src="../../../../component/layui/layui.js"></script>
<script src="../../../../component/pear/pear.js"></script>
<script>
	layui.use(['table','form','jquery'],function () {
		let table = layui.table;
		let form = layui.form;
		let $ = layui.jquery;
		//注意这里的路径，是add按钮和edit按钮的路径
		let MODULE_PATH = "";

		let cols = [
			[
				{title: '档案号', field: 'docNum', align:'center', width:100},
				{title: '老人姓名', field: 'patientName', align:'center'},
				{title: '入住区域', field: 'bedArea', align:'center'},
				{title: '房间', field: 'roomNum', align:'center'},
				{title: '床位号', field: 'bedNum', align:'center'},
				{title: '入住时间', field: 'checkInDate', align:'center'},
				{title: '退住时间', field: 'checkOutDate', align:'center'},
				{title: '结账时间', field: 'checkOutTime', align:'center'},
				{title: '操作', toolbar: '#role-bar', align:'center', width:195}
			]
		]

		table.render({
			elem: '#village_table',
			url: 'http://localhost:8080/checkout/queryAll',
			page: true ,
			cols: cols ,
			skin: 'line',
			toolbar: '#role-toolbar',
			headers: {
				token: localStorage.getItem("token")
			},
			defaultToolbar: [{
				layEvent: 'refresh',
				icon: 'layui-icon-refresh',
			}, 'filter', 'print', 'exports']
		});

		table.on('tool(village_table)', function(obj){
			if(obj.event === 'remove'){
				window.remove(obj);
			} else if(obj.event === 'check'){
				window.check(obj);
			} else if(obj.event === 'power'){
				window.power(obj);
			}
		});

		table.on('toolbar(village_table)', function(obj){
			if(obj.event === 'add'){
				window.add();
			} else if(obj.event === 'refresh'){
				window.refresh();
			} else if(obj.event === 'batchRemove'){
				window.batchRemove(obj);
			}
		});
      //搜索按钮
		form.on('submit(village-query)', function (data) {
			console.log(data.field)
			// 发送ajax请求
			$.ajax({
				url: 'http://localhost:8080/checkout/queryAll',
				headers: {
					token: localStorage.getItem("token")
				},
				method: 'get',
				data: data.field,
				success: function (response) {
					console.log(response)
					table.reload('village_table', { where: data.field })
				},

			});
			return false;
		});

		form.on('switch(goods-enable)', function(obj){
			var checked = obj.elem.checked;
			let status=2;

			if(checked==true){
				status=1;
			}

			$.ajax({
				url:'http://www.j236.com/admin/goods/updateStatus',
				data:{
					"goodsId":this.value,
					"status":status
				},
				type:'post',
				success:function(result){
					layer.alert("操作成功!");
					form.render();
				}
			})

		});

		window.add = function(){
			layer.open({
				type: 2,
				title: '新增',
				shade: 0.1,
				maxmin: true,
				area: ['1000px', '600px'],
				content: MODULE_PATH + 'add.html'
			});
		}

         //查看详情
		window.check = function(obj){

			var data=obj.data;
			var temp;
			if (data.patientSex===1){
				temp="男";
			}else{
				temp="女";
			}
			layer.open({
				type: 2,
				title: '查看详情',
				shade: 0.1,
				area: ['1000px', '600px'],
				content: MODULE_PATH +'details.html?id='+obj.data.id
				,success: function (layero,index){
					var body = layer.getChildFrame("body",index);
					console.log(data)
					var contentWindow = layero.find('iframe')[0].contentWindow;//得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();

					body.find("input[name=id]").val(data.id);
					body.find("input[name=docNum]").val(data.docNum);
					body.find("input[name=patientName]").val(data.patientName);
					body.find("input[name=patientSex]").val(temp);
					body.find("input[name=patientCardId]").val(data.patientCardId);

					body.find("input[name=bedArea]").val(data.bedArea);
					body.find("input[name=roomNum]").val(data.roomNum);
					body.find("input[name=bedNum]").val(data.bedNum);
					body.find("input[name=checkInDate]").val(data.checkInDate);
					body.find("input[name=checkOutDate]").val(data.checkOutDate);
					body.find("input[name=checkTimes]").val(data.checkTimes);
					body.find("input[name=comment]").val(data.comment);
					body.find("input[name=preMoney]").val(data.preMoney);
					body.find("input[name=shouldChargedMoney]").val(data.shouldChargedMoney);
					body.find("input[name=realChargedMoney]").val(data.realChargedMoney);
					body.find("input[name=preBalance]").val(data.preBalance);
					body.find("input[name=billedAmount]").val(data.billedAmount);
					body.find("input[name=returnedAmount]").val(data.returnedAmount);
				}
			});
		}

		window.remove = function(obj){
			layer.confirm('确定要删除该档案', {icon: 3, title:'提示'}, function(index){
				layer.close(index);
				let loading = layer.load();
				$.ajax({
					url:'http://localhost:8080/checkout/delete',
					headers: {
						token: localStorage.getItem("token")
					},
					data:{
						"id":obj.data['id']
					},
					type:'get',
					success:function(result){

						layer.close(loading);
						if(result.code==0){
							layer.msg(result.msg,{icon:1,time:1000},function(){
								obj.del();//前端的假删除
							});
						}else{
							layer.msg(result.msg,{icon:2,time:1000});
						}
					}
				})

			});
		}



		window.refresh = function(){
			table.reload('village_table');
		}
	})
</script>
</body>
</html>
